<template>
  <div>
    <div class="item" v-for="(item,index) in list" :key="index">
      <a-row type="flex" justify="center" align="center" style="margin-top: 5px">
        <a-col :span="1">
          <a-avatar shape="square" size="small">
            <template #icon>
              <a-image style="border-radius: 10px;" :src="'/api'+item.authorAvatar"
                       :preview="false"></a-image>
            </template>
          </a-avatar>
        </a-col>
        <a-col :span="23">
          <a-typography-paragraph
              :style=" { width: '95%' ,fontSize:'17px' } "
              :ellipsis="{rows:3}"
          >{{ item.authorName }} {{ item.time }} 发表
          </a-typography-paragraph>
        </a-col>
      </a-row>
      <a-row type="flex" justify="center" align="center">
        <a-col :span="24">
          <a-typography-title
              :level="4"
              :style=" { width: '95%' } "
              :ellipsis="{rows:3}"
              @click="toDetail(item)"
          >{{ item.title }}
          </a-typography-title>
        </a-col>
      </a-row>

      <a-row type="flex" justify="center" align="center" v-if="item.img===null">
        <a-col :span="24">
          <a-typography-paragraph
              :ellipsis="{rows: 2}"
              v-html=" item.content"
          >
          </a-typography-paragraph>
        </a-col>
      </a-row>

      <a-row style="height: 108px;margin-bottom: 10px" v-else>
        <a-col :span="5">
          <a-image :src="item.img" style="width: 144px;height: 108px;border-radius: 3px"></a-image>
        </a-col>

        <a-col :span="19" style="padding-right: 5px">
          <div style="padding-left: 5px">
            <a-typography-paragraph
                style="line-height:24px;letter-spacing:2px;"
                :ellipsis="{rows: 3}"
                v-html=" item.content"
            >
            </a-typography-paragraph>
          </div>
        </a-col>
      </a-row>


      <a-row type="flex" justify="center" align="center" style="height: 20px">
        <a-col :span="10">
          <a-row type="flex" justify="space-around" align="center" style="height: 20px">


            <a-col :span="5">
              <div v-if="item.like===false" style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>点赞</template>
                    <like-two-tone two-tone-color=rgb(85,85,85) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.likeCount }}</div>
              </div>
              <div v-else style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>已点赞</template>
                    <like-two-tone two-tone-color=rgb(0,102,255) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.likeCount }}</div>
              </div>
            </a-col>

            <a-col :span="5">
              <div v-if="item.collect===false" style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>收藏</template>
                    <heart-two-tone two-tone-color=rgb(85,85,85) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.collectCount }}</div>
              </div>
              <div v-else style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>已收藏</template>
                    <heart-two-tone two-tone-color=rgb(0,102,255) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.collectCount }}</div>
              </div>
            </a-col>

            <a-col :span="5">
              <div v-if="item.followPost===false" style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>关注</template>
                    <tag-two-tone two-tone-color=rgb(85,85,85) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.followPostCount }}</div>
              </div>
              <div v-else style="display: flex;align-items: center">
                <div>
                  <a-tooltip>
                    <template #title>已关注</template>
                    <tag-two-tone two-tone-color=rgb(0,102,255) :style="{fontSize: '16px'}"/>
                  </a-tooltip>
                </div>
                <div style="margin-left: 5px">{{ item.followPostCount }}</div>
              </div>
            </a-col>

            <a-col :span="9">
              <div style="display: flex;align-items: center">
                <div>
                  <message-two-tone two-tone-color=rgb(85,85,85) :style="{fontSize: '16px'}"/>
                </div>
                <div style="margin-left: 5px">{{ item.commentCount }}</div>
                <div>条评论</div>
              </div>
            </a-col>

          </a-row>
        </a-col>
        <a-col :span="14">
          <a-button size="small" v-for="(i,index) in item.labels" :key="index" disabled style="margin-left: 10px">
            {{ i.name }}
          </a-button>
        </a-col>
      </a-row>
    </div>


  </div>

</template>
<script>
import {LikeTwoTone, MessageTwoTone, HeartTwoTone, TagTwoTone} from '@ant-design/icons-vue';
import {useRouter} from "vue-router";


export default {
  components: {HeartTwoTone, LikeTwoTone, MessageTwoTone, TagTwoTone},
  name: "PostList",
  props: {
    list: {
      type: Array,
    }
  },
  setup(props, {emit}) {
    const router = useRouter(); //获取路由器

    const toDetail = (item) => {
      router.push({
        path: '/postDetail',
        query: {item: encodeURIComponent(JSON.stringify(item))}
      })
    };
    return {
      toDetail,
    };
  },
};
</script>
<style scoped>
.item {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  margin-bottom: 10px;
  padding: 9px 20px;
  background-color: rgb(245, 245, 245);
}
</style>